package cn.springcloud.fix.mybatis.starter;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;

import java.util.Properties;

@Configuration
@Import(MyMetaObjectHandler.class)
@MapperScan({"cn.springcloud.fix.*.dao.mapper"})
public class MybatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    @ConditionalOnMissingBean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setLimit(1000);//设置分页pageSize
        return paginationInterceptor;
    }

    /**
     * 打印 sql【生产环境可以关闭】
     */
    @Bean
    @Profile({"dev", "test", "sit"})
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        Properties properties = new Properties();
        properties.setProperty("format", "true");//格式化sql语句
        performanceInterceptor.setProperties(properties);
        return performanceInterceptor;
    }
}
